﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace VTNT.Framework.Web.Global
{
    public class CCookies : CHttpContext
    {
        public static string GetCookies(string key)
        {
            HttpCookie cookie = Request.Cookies[key];
            if (cookie != null)
            {
                return cookie.Value;
            }
            else
            {
                return "";
            }
        }
        public static void SetCookies(string key, string value)
        {
            HttpCookie cookies = new HttpCookie(key);
            cookies.Value = value;
            cookies.Expires = DateTime.Now + new TimeSpan(24, 0, 0);
            Response.Cookies.Add(cookies);
        }
        public static void SetCookies(string key, string value, DateTime expiredTime)
        {
            HttpCookie cookies = new HttpCookie(key);
            cookies.Value = value;
            cookies.Expires = expiredTime;
            Response.Cookies.Add(cookies);
        }
        public static void DeleteCookies(string key)
        {
            if (HttpContext.Current.Request.Cookies[key] != null)
                HttpContext.Current.Response.Cookies[key].Expires = DateTime.Now.AddDays(-10);
        }

        #region PUBLIC STATIC
        protected static string _languageID = "iCMS:LanguageID";

        public static void SetLanguageID(string value)
        {
            SetCookies(_languageID, value);
        }
        public static string GetLanguageID()
        {
            string languageID = GetCookies(_languageID);
            if (string.IsNullOrEmpty(languageID))
            {
                languageID = "129";
            }
            return languageID;
        }
        #endregion
    }
}